#!/usr/bin/env python3
import json
import pandas as pd
from ..utils import fetch_url, st_get_api

def get_switch_stats(switch_idx: int):
    end_point = 'stats/desc/' + str(switch_idx)
    url, time_out = st_get_api(end_point)
    try:
        switch_stats = fetch_url(url, time_out)
        df = pd.DataFrame.from_dict(switch_stats, orient='index')
        df.reset_index(drop=True, inplace=True)
        df.columns = ['Manufacturer Description', 'Hardware Description', 'Software Description', 'Serial Number', 'Data Path Description']
        return json.dumps(switch_stats, indent=4), df
    except Exception as e:
        raise
